package org.chenyuepan.pojo;

import java.util.ArrayList;
import java.util.List;

public class Student {

    private String id;

    private String name;

    private List<Course> courses;

    public Student() {
    }

    public Student(String id, String name, List<Course> courses) {
        this.id = id;
        this.name = name;
        this.courses = courses;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Course> getCourses() {
        return courses;
    }

    public void setCourses(List<Course> courses) {
        this.courses = courses;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", courses=" + courses +
                '}';
    }

    /**
     * 删除一门课程
     * @param courseName
     */
    public void removeCourse(String courseName) {
        List<Course> toKeep = new ArrayList<>();
        courses.forEach(course -> {
            if (!course.getCname().equals(courseName)) {
                toKeep.add(course);
            }
        });
        courses.clear();
        courses.addAll(toKeep);
    }

}
